﻿using System;
using System.Linq;
using Styx;
using Styx.Helpers;
using Styx.Plugins.PluginClass;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

namespace Smarter
{
    public class Smarter : HBPlugin
    {
        private bool _firstPulse = true;
        private readonly WaitTimer _itemCheckTimer = new WaitTimer(new TimeSpan(0, 0, 5, 0));
        private readonly LocalPlayer _me = ObjectManager.Me;

        public override void Pulse()
        {
            if (_firstPulse)
            {

                _firstPulse = false;
            }

            if (_itemCheckTimer.IsFinished)
            {
                SatchelCheck();
                _itemCheckTimer.Reset();
            }

        }


        private void MoteCheck()
        {
            if (!_me.BagItems.Exists(o => o.Name.Contains("Mote"))) return;
            var items = _me.BagItems.Where(o => o.Name.Contains("Mote of"));
            for (int i = 0; i < items.Count(); i++)
            {
                items.First().Use(true);
                StyxWoW.SleepForLagDuration();
            }
        }
        private void SatchelCheck()
        {
            if (!_me.BagItems.Exists(o => o.Name == "Satchel of Helpful Goods")) return;
            var items = _me.BagItems.Where(o => o.Name == "Satchel of Helpful Goods");
            for (var i = 0; i < items.Count(); i++)
            {
                items.First().Use(true);
                StyxWoW.SleepForLagDuration();
            }
        }

        public override string Name
        {
            get { return "Smarter"; }
        }

        public override string Author
        {
            get { return "Smarter"; }
        }

        public override Version Version
        {
            get { return new Version(0,0,1,0); }
        }
    }
}
